#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# @Project:     src-server
# @File:        prj_api.py
# @Author:      Fan GuiChuan
# @Date:        2025/10/14 15:12
# @Version:     Python3.7
# @Description:
import requests
from flask import request

from app.services.prj_info_serv import PrjInfoServ
from app.utils.response import success_response, error_response


class PrjApi:
    """
    项目管理接口类
    """
    def __init__(self, logger, blueprint):
        self.logger = logger
        self.prj_info_serv = PrjInfoServ(logger)
        self.blueprint = blueprint
        self.register_blueprint()

    def register_blueprint(self):
        """
        注册蓝图
        """
        self.blueprint.add_url_rule('/add_prj', view_func=self.add_prj, methods=['POST'])
        self.blueprint.add_url_rule('/delete_prj', view_func=self.delete_prj, methods=['POST'])
        self.blueprint.add_url_rule('/update_prj', view_func=self.update_prj, methods=['POST'])
        self.blueprint.add_url_rule('/find_prj', view_func=self.find_prj, methods=['POST'])
        self.blueprint.add_url_rule('/get_prj_list', view_func=self.get_prj_list, methods=['POST'])

    def add_prj(self):
        """
        新增项目接口
        """
        try:
            ret, data = self.prj_info_serv.add_prj()
            if ret:
                return success_response(data)
            else:
                return error_response(data)
        except Exception as e:
            self.logger.exception(str(e))
            return error_response(str(e))

    def delete_prj(self):
        """
        删除项目接口
        """
        pass

    def update_prj(self):
        """
        更新项目接口
        """
        pass

    def find_prj(self):
        """
        查找项目
        """
        pass

    def get_prj_list(self):
        """
        获取项目列表
        """
        ret, data = self.prj_info_serv.get_prj_list()
        if ret:
            return success_response(data)
        return error_response(data)
